/**
 * Created by fuhao on 15/9/2.
 */
;
var $ = jQuery;
function validateReqStatus(data, callback) {
    if (data != null && data.errorCode != "0") {
        if (callback) {
            callback();
        }
    } else {
        var msg = data.message == undefined ? data.msg : data.message;
        $.messager.alert('操作失败', (msg == "" || msg == undefined) ? '操作失败' : msg);
    }
}

(function ($) {
    $.fn.serializeJson = function () {
        var serializeObj = {};
        var array = this.serializeArray();
        $(array).each(function () {
            if (serializeObj[this.name]) {
                if ($.isArray(serializeObj[this.name])) {
                    serializeObj[this.name].push(this.value);
                } else {
                    serializeObj[this.name] = [serializeObj[this.name], this.value];
                }
            } else {
                serializeObj[this.name] = this.value;
            }
        });
        return serializeObj;
    };
})(jQuery);

$(function() {
    $('.forbiddenNumber').die('keyup').live('keyup', function (e) {
        var c = $(this);
        if (/[^\d]/.test(c.val())) {
            var temp_amount = c.val().replace(/[^\d]/g, '');
            $(this).val(temp_amount);
        }
    });
});

function isEmpty(str) {
    if (str == undefined) {
        return true;
    }
    if ($.trim(str) == "") {
        return true;
    }
    return false;
}

function resetInput($this) {
    $($this).parents('form').get(0).reset();
    $('[name=createTimeStart]').val('');
    $('[name=createTimeEnd]').val('');
}

function formateDate(dd) {
    var zr = function (n) {
        return n < 10 ? '0' + n : n;
    }
    return (dd.getFullYear() + '-' + zr(dd.getMonth() + 1) + '-' + zr(dd.getDate()) + ' ' + zr(dd.getHours()) + ':' + zr(dd.getMinutes()));
}
